<?php

session_start(); 

if(strpos(curPageURL(),"closesession")!==false) {
    session_destroy();
    $_SESSION['token']="";
}

if(isset($_SESSION['currentPage'])) {
    $_SESSION['previousPage'] =$_SESSION['currentPage'];
}
$_SESSION['currentPage'] =curPageURL();

function my_ucfirst($string, $e ='utf-8') { 
    if (function_exists('mb_strtoupper') && function_exists('mb_substr') && !empty($string)) { 
        $string = mb_strtolower($string, $e); 
        $upper = mb_strtoupper($string, $e); 
            preg_match('#(.)#us', $upper, $matches); 
            $string = $matches[1] . mb_substr($string, 1, mb_strlen($string, $e), $e); 
    } 
    else { 
        $string = ucfirst($string); 
    } 
    return $string; 
}

function sentence_case($string) { 
    $sentences = preg_split('/([.?!]+)/', $string, -1, PREG_SPLIT_NO_EMPTY|PREG_SPLIT_DELIM_CAPTURE); 
    $new_string = ''; 
    foreach ($sentences as $key => $sentence) { 
        $new_string .= ($key & 1) == 0? 
            my_ucfirst(strtolower(trim($sentence))) : 
            $sentence.' ';  
    } 
    return trim($new_string); 
}

function curPageURL() {
 $pageURL = 'http';
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

?>